#include <iostream>
#include <memory>

struct C : std::enable_shared_from_this<C> {
    int x;
};

int main()
{
    std::shared_ptr<C> foo, bar;

    foo = std::make_shared<C>();
    foo->x = 19;

    bar = foo->shared_from_this();

    std::cout << "bar.x: " << bar->x << std::endl;

    return 0;
}
